package edu.uic.keyoutcomestrackertool.fragments;

import edu.uic.keyoutcomestrackertool.R;
import edu.uic.keyoutcomestrackertool.TrackKeyOutcomes;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CalendarView;
import android.widget.TextView;

import java.util.Calendar;

import android.widget.CalendarView.OnDateChangeListener;

public class FragmentCalendarView extends Fragment {
	
	//public static TextView textview_date_focused;
	public static String date_focused;
	public static CalendarView calendar_track_key_outcomes;
	public static int mYear;
	public static int mMonth;
	public static int mDay;
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		//Inflate calendar_view.xml as fragment
		View calendar_view = inflater.inflate(R.layout.calendar_view, container, false);
		
		//textview_date_focused = (TextView) calendar_view.findViewById(R.id.textview_date_focused);
		calendar_track_key_outcomes = (CalendarView) calendar_view.findViewById(R.id.calendar_track_key_outcomes);
		CalendarOnDateChangeListener();
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH) + 1; //January = 0
		mDay = c.get(Calendar.DAY_OF_MONTH);
		updateDate();
		
		
		return calendar_view;
		}
	
	public static void updateDate() {
		date_focused = mMonth + "/" + mDay + "/" + mYear;
		//textview_date_focused.setText(date_focused);
		TrackKeyOutcomes.UpdateVariables();
		}
	
	
	public static void CalendarOnDateChangeListener () {
		calendar_track_key_outcomes.setOnDateChangeListener(new OnDateChangeListener () {

			@Override
			public void onSelectedDayChange(CalendarView view,
					int year, int month, int dayOfMonth) {
				mYear = year;
				mMonth = month + 1;
				mDay = dayOfMonth;
				updateDate();
			}
		});
	}

}
